﻿namespace WMS6.Web.Analytics
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.AnalyticsReportServiceRef;
    using WMS6.Web.UserControls;

    public class ReceivingList : BasePage
    {
        protected Button btnExport;
        protected Button btnList;
        protected Button btnRefresh;
        protected Button btnReSearch;
        protected Button btnSearch;
        protected HtmlForm F15151;
        protected GridView gvReceipt;
        protected GridView gvReceiptLpn;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdnFrom;
        protected Label lblMsg;
        protected Label lblReceiptInquiryList;
        protected Label lblTotalCube;
        protected Label lblTotalCubeText;
        protected Label lblTotalEeceived;
        protected Label lblTotalEeceivedQty;
        protected Label lblTotalExpected;
        protected Label lblTotalExpectedQty;
        protected Label lblTotalGrossWGT;
        protected Label lblTotalGrossWGTText;
        protected Label lblTotalPrice;
        protected Label lblTotalPriceText;
        protected Label lblTotalWgt;
        protected Label lblTotalWgtText;
        protected HtmlLink mycss;
        protected Pager PagerFooter;
        private List<string> receiptIDList = new List<string>();
        private Dictionary<string, ReceiptQtyDiffInfo> receiptQtyDiffInfoList = new Dictionary<string, ReceiptQtyDiffInfo>();
        protected ScriptManager ScriptManager1;
        private decimal TotalCube;
        private decimal TotalExpectedQty;
        private decimal TotalGrossWGT;
        private decimal TotalPrice;
        private decimal TotalReceivedQty;
        private decimal TotalWgt;
        protected UpdatePanel up1;

        private void BindData2ReceiptList(ReceiptDetailRptQueryEntity receiptQuery)
        {
            this.PagerFooter.CurrentPage = int.Parse(receiptQuery.CurrentPage);
            DataSet ds = AnalyticsReportServiceClientProxy.GetInstance().GetReceiptDetailRptInfo(receiptQuery);
            if (receiptQuery.SHOW_LPN)
            {
                this.gvReceiptLpn.Visible = true;
                this.gvReceipt.Visible = false;
                base.BindData2GridView(this.gvReceiptLpn, ds);
                this.SetDiffColor(this.gvReceiptLpn);
            }
            else
            {
                this.gvReceiptLpn.Visible = false;
                this.gvReceipt.Visible = true;
                base.BindData2GridView(this.gvReceipt, ds);
                this.SetDiffColor(this.gvReceipt);
            }
            if ((ds != null) && (ds.Tables.Count > 1))
            {
                this.PagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                this.PagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            ReceiptDetailRptQueryEntity receiptQuery = this.GetReceiptQueryEntity();
            receiptQuery.IsGetAll = true;
            this.hdnActionID.Value = "EXPORT";
            string currentPageIndex = receiptQuery.CurrentPage;
            receiptQuery.CurrentPage = "0";
            try
            {
                using (DataSet ds = AnalyticsReportServiceClientProxy.GetInstance().GetReceiptDetailRptInfo(receiptQuery))
                {
                    ds.Tables[0].Columns.Remove("UNIT_PRICE");
                    ds.Tables[0].Columns.Remove("PRICE");
                    if (receiptQuery.SHOW_LPN)
                    {
                        base.Export2Excel("ReceivingRpt.xls", "15151", this.gvReceiptLpn, ds);
                    }
                    else
                    {
                        base.Export2Excel("ReceivingRpt.xls", "15151", this.gvReceipt, ds);
                    }
                }
            }
            finally
            {
                receiptQuery.IsGetAll = false;
                receiptQuery.CurrentPage = currentPageIndex;
                this.SetReceiptQueryEntity(receiptQuery);
            }
        }

        protected void btnFirst_Click(object sender, EventArgs e)
        {
            ReceiptDetailRptQueryEntity receiptQuery = this.GetReceiptQueryEntity();
            receiptQuery.CurrentPage = "0";
            this.BindData2ReceiptList(receiptQuery);
        }

        protected void btnLast_Click(object sender, EventArgs e)
        {
            ReceiptDetailRptQueryEntity receiptQuery = this.GetReceiptQueryEntity();
            receiptQuery.CurrentPage = (this.PagerFooter.TotalPages - 1).ToString();
            this.BindData2ReceiptList(receiptQuery);
        }

        protected void btnList_Click(object sender, EventArgs e)
        {
            ReceiptDetailRptQueryEntity receiptQuery = this.GetReceiptQueryEntity();
            receiptQuery.RECEIPT_ID = "";
            receiptQuery.OWNER_ID = "";
            receiptQuery.PO_ID = "";
            receiptQuery.EXTERN_RECEIPT_ID = "";
            receiptQuery.RECEIPT_TYPE = "";
            receiptQuery.STARTRECEIVED_DATE = "";
            receiptQuery.ENDRECEIVED_DATE = "";
            receiptQuery.SKU_CLASS_ID = "";
            receiptQuery.SKU_ID = "";
            receiptQuery.DESCR = "";
            receiptQuery.VENDOR_ID = "";
            receiptQuery.RMA = "";
            receiptQuery.SHOW_LPN = false;
            receiptQuery.LOT_ATTR01 = "";
            receiptQuery.LOT_ATTR02 = "";
            receiptQuery.LOT_ATTR03 = "";
            receiptQuery.LOT_ATTR04 = "";
            receiptQuery.LOT_ATTR05 = "";
            receiptQuery.LOT_ATTR06 = "";
            receiptQuery.LOT_ATTR07 = "";
            receiptQuery.LOT_ATTR08 = "";
            receiptQuery.LOT_ATTR09 = "";
            receiptQuery.LOT_ATTR10 = "";
            receiptQuery.PRODUCE_DATE = "";
            receiptQuery.EXPIRY_DATE = "";
            receiptQuery.EXTERNAL_LOT = "";
            this.BindData2ReceiptList(receiptQuery);
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            ReceiptDetailRptQueryEntity receiptQuery = this.GetReceiptQueryEntity();
            if (int.Parse(receiptQuery.CurrentPage) < (this.PagerFooter.TotalPages - 1))
            {
                receiptQuery.CurrentPage = (int.Parse(receiptQuery.CurrentPage) + 1).ToString();
                this.BindData2ReceiptList(receiptQuery);
            }
        }

        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            ReceiptDetailRptQueryEntity receiptQuery = this.GetReceiptQueryEntity();
            if (int.Parse(receiptQuery.CurrentPage) > 0)
            {
                receiptQuery.CurrentPage = (int.Parse(receiptQuery.CurrentPage) - 1).ToString();
                this.BindData2ReceiptList(receiptQuery);
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            ReceiptDetailRptQueryEntity receiptQuery = this.GetReceiptQueryEntity();
            this.BindData2ReceiptList(receiptQuery);
        }

        private ReceiptDetailRptQueryEntity GetReceiptQueryEntity()
        {
            return (base.PageQueryEntitySession as ReceiptDetailRptQueryEntity);
        }

        protected void GoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                ReceiptDetailRptQueryEntity receiptQuery = this.GetReceiptQueryEntity();
                receiptQuery.CurrentPage = this.PagerFooter.GoToPage.ToString();
                this.BindData2ReceiptList(receiptQuery);
            }
        }

        protected void gvReceipt_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F15111", this.gvReceipt);
        }

        protected void gvReceipt_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                e.Row.Attributes.Add("ondblclick", "JavaScript:document.getElementById('" + ((CheckBox) e.Row.FindControl("chbSelect")).ClientID + "').click();");
                if (this.hdnActionID.Value != "EXPORT")
                {
                    base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
                }
                if ((((Label) e.Row.FindControl("lblReceiptID")) != null) && (((Label) e.Row.FindControl("lblReceiptLineID")) != null))
                {
                    ReceiptQtyDiffInfo receiptQtyDiffInfo;
                    if (!this.receiptIDList.Contains(((Label) e.Row.FindControl("lblReceiptID")).Text + "," + ((Label) e.Row.FindControl("lblReceiptLineID")).Text))
                    {
                        this.receiptIDList.Add(((Label) e.Row.FindControl("lblReceiptID")).Text + "," + ((Label) e.Row.FindControl("lblReceiptLineID")).Text);
                        receiptQtyDiffInfo = new ReceiptQtyDiffInfo {
                            RowIndex = e.Row.RowIndex,
                            OrderQty = decimal.Parse(string.IsNullOrEmpty(((Label) e.Row.FindControl("lblExpectedQty")).Text) ? "0" : ((Label) e.Row.FindControl("lblExpectedQty")).Text),
                            ReceivedQty = decimal.Parse(string.IsNullOrEmpty(((Label) e.Row.FindControl("lblReceivedQty")).Text) ? "0" : ((Label) e.Row.FindControl("lblReceivedQty")).Text)
                        };
                        this.receiptQtyDiffInfoList.Add(((Label) e.Row.FindControl("lblReceiptID")).Text + "," + ((Label) e.Row.FindControl("lblReceiptLineID")).Text, receiptQtyDiffInfo);
                    }
                    else
                    {
                        ((Label) e.Row.FindControl("lblExpectedQty")).Text = "";
                        receiptQtyDiffInfo = this.receiptQtyDiffInfoList[((Label) e.Row.FindControl("lblReceiptID")).Text + "," + ((Label) e.Row.FindControl("lblReceiptLineID")).Text];
                        receiptQtyDiffInfo.ReceivedQty += decimal.Parse(string.IsNullOrEmpty(((Label) e.Row.FindControl("lblReceivedQty")).Text) ? "0" : ((Label) e.Row.FindControl("lblReceivedQty")).Text);
                        this.receiptQtyDiffInfoList[((Label) e.Row.FindControl("lblReceiptID")).Text + "," + ((Label) e.Row.FindControl("lblReceiptLineID")).Text] = receiptQtyDiffInfo;
                    }
                }
                if ((((Label) e.Row.FindControl("lblReceivedQty")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblReceivedQty")).Text))
                {
                    this.TotalReceivedQty += decimal.Parse(((Label) e.Row.FindControl("lblReceivedQty")).Text);
                }
                if ((((Label) e.Row.FindControl("lblExpectedQty")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblExpectedQty")).Text))
                {
                    this.TotalExpectedQty += decimal.Parse(((Label) e.Row.FindControl("lblExpectedQty")).Text);
                }
                if ((((Label) e.Row.FindControl("lblPRICE")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblPRICE")).Text))
                {
                    this.TotalPrice += decimal.Parse(((Label) e.Row.FindControl("lblPRICE")).Text);
                }
                if ((((Label) e.Row.FindControl("lblTOTAL_WGT")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblTOTAL_WGT")).Text))
                {
                    this.TotalWgt += decimal.Parse(((Label) e.Row.FindControl("lblTOTAL_WGT")).Text);
                }
                if ((((Label) e.Row.FindControl("lblTOTAL_GROSS_WGT")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblTOTAL_GROSS_WGT")).Text))
                {
                    this.TotalGrossWGT += decimal.Parse(((Label) e.Row.FindControl("lblTOTAL_GROSS_WGT")).Text);
                }
                if ((((Label) e.Row.FindControl("lblTOTAL_CUBE")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblTOTAL_CUBE")).Text))
                {
                    this.TotalCube += decimal.Parse(((Label) e.Row.FindControl("lblTOTAL_CUBE")).Text);
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblTotalEeceivedQty.Text = base.GetPreferenceDigit(this.TotalReceivedQty);
                this.lblTotalExpectedQty.Text = base.GetPreferenceDigit(this.TotalExpectedQty);
                this.lblTotalPriceText.Text = base.GetPreferenceDigit(this.TotalPrice);
                this.lblTotalCubeText.Text = base.GetPreferenceDigit(this.TotalCube);
                this.lblTotalGrossWGTText.Text = base.GetPreferenceDigit(this.TotalGrossWGT);
                this.lblTotalWgtText.Text = base.GetPreferenceDigit(this.TotalWgt);
            }
        }

        protected void gvReceipt_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                ReceiptDetailRptQueryEntity receiptQuery = this.GetReceiptQueryEntity();
                receiptQuery.SortField = e.SortExpression;
                if (receiptQuery.SortDirection == "ASC")
                {
                    receiptQuery.SortDirection = "DESC";
                }
                else if (receiptQuery.SortDirection == "DESC")
                {
                    receiptQuery.SortDirection = "ASC";
                }
                this.BindData2ReceiptList(receiptQuery);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        protected void gvReceiptLpn_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F15111", this.gvReceiptLpn);
        }

        protected void gvReceiptLpn_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                e.Row.Attributes.Add("ondblclick", "JavaScript:document.getElementById('" + ((CheckBox) e.Row.FindControl("chbSelect")).ClientID + "').click();");
                if (this.hdnActionID.Value != "EXPORT")
                {
                    base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
                }
                if ((((Label) e.Row.FindControl("lblReceiptID")) != null) && (((Label) e.Row.FindControl("lblReceiptLineID")) != null))
                {
                    ReceiptQtyDiffInfo receiptQtyDiffInfo;
                    if (!this.receiptIDList.Contains(((Label) e.Row.FindControl("lblReceiptID")).Text + "," + ((Label) e.Row.FindControl("lblReceiptLineID")).Text))
                    {
                        this.receiptIDList.Add(((Label) e.Row.FindControl("lblReceiptID")).Text + "," + ((Label) e.Row.FindControl("lblReceiptLineID")).Text);
                        receiptQtyDiffInfo = new ReceiptQtyDiffInfo {
                            RowIndex = e.Row.RowIndex,
                            OrderQty = decimal.Parse(string.IsNullOrEmpty(((Label) e.Row.FindControl("lblExpectedQty")).Text) ? "0" : ((Label) e.Row.FindControl("lblExpectedQty")).Text),
                            ReceivedQty = decimal.Parse(string.IsNullOrEmpty(((Label) e.Row.FindControl("lblReceivedQty")).Text) ? "0" : ((Label) e.Row.FindControl("lblReceivedQty")).Text)
                        };
                        this.receiptQtyDiffInfoList.Add(((Label) e.Row.FindControl("lblReceiptID")).Text + "," + ((Label) e.Row.FindControl("lblReceiptLineID")).Text, receiptQtyDiffInfo);
                    }
                    else
                    {
                        ((Label) e.Row.FindControl("lblExpectedQty")).Text = "";
                        receiptQtyDiffInfo = this.receiptQtyDiffInfoList[((Label) e.Row.FindControl("lblReceiptID")).Text + "," + ((Label) e.Row.FindControl("lblReceiptLineID")).Text];
                        receiptQtyDiffInfo.ReceivedQty += decimal.Parse(string.IsNullOrEmpty(((Label) e.Row.FindControl("lblReceivedQty")).Text) ? "0" : ((Label) e.Row.FindControl("lblReceivedQty")).Text);
                        this.receiptQtyDiffInfoList[((Label) e.Row.FindControl("lblReceiptID")).Text + "," + ((Label) e.Row.FindControl("lblReceiptLineID")).Text] = receiptQtyDiffInfo;
                    }
                }
                if ((((Label) e.Row.FindControl("lblReceivedQty")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblReceivedQty")).Text))
                {
                    this.TotalReceivedQty += decimal.Parse(((Label) e.Row.FindControl("lblReceivedQty")).Text);
                }
                if ((((Label) e.Row.FindControl("lblExpectedQty")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblExpectedQty")).Text))
                {
                    this.TotalExpectedQty += decimal.Parse(((Label) e.Row.FindControl("lblExpectedQty")).Text);
                }
                if ((((Label) e.Row.FindControl("lblPRICE")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblPRICE")).Text))
                {
                    this.TotalPrice += decimal.Parse(((Label) e.Row.FindControl("lblPRICE")).Text);
                }
                if ((((Label) e.Row.FindControl("lblTOTAL_WGT")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblTOTAL_WGT")).Text))
                {
                    this.TotalWgt += decimal.Parse(((Label) e.Row.FindControl("lblTOTAL_WGT")).Text);
                }
                if ((((Label) e.Row.FindControl("lblTOTAL_GROSS_WGT")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblTOTAL_GROSS_WGT")).Text))
                {
                    this.TotalGrossWGT += decimal.Parse(((Label) e.Row.FindControl("lblTOTAL_GROSS_WGT")).Text);
                }
                if ((((Label) e.Row.FindControl("lblTOTAL_CUBE")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblTOTAL_CUBE")).Text))
                {
                    this.TotalCube += decimal.Parse(((Label) e.Row.FindControl("lblTOTAL_CUBE")).Text);
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblTotalEeceivedQty.Text = base.GetPreferenceDigit(this.TotalReceivedQty);
                this.lblTotalExpectedQty.Text = base.GetPreferenceDigit(this.TotalExpectedQty);
                this.lblTotalPriceText.Text = base.GetPreferenceDigit(this.TotalPrice);
                this.lblTotalCubeText.Text = base.GetPreferenceDigit(this.TotalCube);
                this.lblTotalGrossWGTText.Text = base.GetPreferenceDigit(this.TotalGrossWGT);
                this.lblTotalWgtText.Text = base.GetPreferenceDigit(this.TotalWgt);
            }
        }

        protected void gvReceiptLpn_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                ReceiptDetailRptQueryEntity receiptQuery = this.GetReceiptQueryEntity();
                receiptQuery.SortField = e.SortExpression;
                if (receiptQuery.SortDirection == "ASC")
                {
                    receiptQuery.SortDirection = "DESC";
                }
                else if (receiptQuery.SortDirection == "DESC")
                {
                    receiptQuery.SortDirection = "ASC";
                }
                this.BindData2ReceiptList(receiptQuery);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void LoadData()
        {
            ReceiptDetailRptQueryEntity receiptQuery = new ReceiptDetailRptQueryEntity();
            if (string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                if (this.PreviousPage != null)
                {
                    receiptQuery.RECEIPT_ID = this.PreviousPage.ReceiptID;
                    receiptQuery.OWNER_ID = this.PreviousPage.OwnerID;
                    receiptQuery.PO_ID = this.PreviousPage.PoID;
                    receiptQuery.EXTERN_RECEIPT_ID = this.PreviousPage.ExtenalReceiptID;
                    receiptQuery.RECEIPT_TYPE = this.PreviousPage.ReceiptType;
                    receiptQuery.STARTRECEIVED_DATE = this.PreviousPage.StartReceivedDate;
                    receiptQuery.ENDRECEIVED_DATE = this.PreviousPage.EndReceivedDate;
                    receiptQuery.SKU_CLASS_ID = this.PreviousPage.SkuClassID;
                    receiptQuery.SKU_ID = this.PreviousPage.SkuID;
                    receiptQuery.VENDOR_ID = this.PreviousPage.VendorID;
                    receiptQuery.RMA = this.PreviousPage.Rma;
                    receiptQuery.DESCR = this.PreviousPage.SkuName;
                    receiptQuery.SHOW_LPN = this.PreviousPage.ShowLpn;
                    receiptQuery.LOT_ATTR01 = this.PreviousPage.LotAttribute01;
                    receiptQuery.LOT_ATTR02 = this.PreviousPage.LotAttribute02;
                    receiptQuery.LOT_ATTR03 = this.PreviousPage.LotAttribute03;
                    receiptQuery.LOT_ATTR04 = this.PreviousPage.LotAttribute04;
                    receiptQuery.LOT_ATTR05 = this.PreviousPage.LotAttribute05;
                    receiptQuery.LOT_ATTR06 = this.PreviousPage.LotAttribute06;
                    receiptQuery.LOT_ATTR07 = this.PreviousPage.LotAttribute07;
                    receiptQuery.LOT_ATTR08 = this.PreviousPage.LotAttribute08;
                    receiptQuery.LOT_ATTR09 = this.PreviousPage.LotAttribute09;
                    receiptQuery.LOT_ATTR10 = this.PreviousPage.LotAttribute10;
                    receiptQuery.PRODUCE_DATE = this.PreviousPage.ProduceDate;
                    receiptQuery.EXPIRY_DATE = this.PreviousPage.ExpiryDate;
                    receiptQuery.EXTERNAL_LOT = this.PreviousPage.ExternalLot;
                }
                else
                {
                    receiptQuery.RECEIPT_ID = "";
                    receiptQuery.OWNER_ID = "";
                    receiptQuery.PO_ID = "";
                    receiptQuery.EXTERN_RECEIPT_ID = "";
                    receiptQuery.RECEIPT_TYPE = "";
                    receiptQuery.STARTRECEIVED_DATE = "";
                    receiptQuery.ENDRECEIVED_DATE = "";
                    receiptQuery.SKU_CLASS_ID = "";
                    receiptQuery.SKU_ID = "";
                    receiptQuery.VENDOR_ID = "";
                    receiptQuery.RMA = "";
                    receiptQuery.DESCR = "";
                    receiptQuery.SHOW_LPN = false;
                    receiptQuery.LOT_ATTR01 = "";
                    receiptQuery.LOT_ATTR02 = "";
                    receiptQuery.LOT_ATTR03 = "";
                    receiptQuery.LOT_ATTR04 = "";
                    receiptQuery.LOT_ATTR05 = "";
                    receiptQuery.LOT_ATTR06 = "";
                    receiptQuery.LOT_ATTR07 = "";
                    receiptQuery.LOT_ATTR08 = "";
                    receiptQuery.LOT_ATTR09 = "";
                    receiptQuery.LOT_ATTR10 = "";
                    receiptQuery.PRODUCE_DATE = "";
                    receiptQuery.EXPIRY_DATE = "";
                    receiptQuery.EXTERNAL_LOT = "";
                }
            }
            else
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            receiptQuery.IsGetAll = false;
            receiptQuery.CurrentPage = "0";
            receiptQuery.PageSize = this.gvReceipt.PageSize.ToString();
            if (receiptQuery.SHOW_LPN)
            {
                receiptQuery.SortField = "RECEIPT_ID DESC,RECEIPT_LINE_ID";
            }
            else
            {
                receiptQuery.SortField = "RECEIPT_ID DESC,SKU_ID";
            }
            receiptQuery.SortDirection = "ASC";
            this.PagerFooter.PageSize = this.gvReceipt.PageSize;
            this.SetReceiptQueryEntity(receiptQuery);
            this.BindData2ReceiptList(receiptQuery);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                base.InitAnalyticsReportGridview(this.gvReceipt);
                base.InitAnalyticsReportGridview(this.gvReceiptLpn);
                this.LoadData();
            }
        }

        private void SetDiffColor(GridView gv)
        {
            foreach (KeyValuePair<string, ReceiptQtyDiffInfo> item in this.receiptQtyDiffInfoList)
            {
                if (item.Value.ReceivedQty != item.Value.OrderQty)
                {
                    ((Label) gv.Rows[item.Value.RowIndex].FindControl("lblExpectedQty")).BackColor = Color.Yellow;
                }
            }
        }

        private void SetReceiptQueryEntity(ReceiptDetailRptQueryEntity receiptQuery)
        {
            base.PageQueryEntitySession = receiptQuery;
        }

        public ReceivingQuery PreviousPage
        {
            get
            {
                return (ReceivingQuery) base.PreviousPage;
            }
        }

        public class ReceiptQtyDiffInfo
        {
            public decimal OrderQty { get; set; }

            public decimal ReceivedQty { get; set; }

            public int RowIndex { get; set; }
        }
    }
}

